package com.example.myapplication2;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // 1. 准备数据
        List<Bus> busList = new ArrayList<>();
        busList.add(new Bus(R.mipmap.ic_launcher, "智慧巴士1路"));
        busList.add(new Bus(R.mipmap.ic_launcher, "智慧巴士2路"));
        busList.add(new Bus(R.mipmap.ic_launcher, "智慧巴士3路"));
        busList.add(new Bus(R.mipmap.ic_launcher, "智慧巴士4路"));
        busList.add(new Bus(R.mipmap.ic_launcher, "智慧巴士5路"));

        // 2. 初始化RecyclerView
        RecyclerView rvBus = findViewById(R.id.rv_bus);
        rvBus.setLayoutManager(new LinearLayoutManager(this));
        rvBus.setAdapter(new BusAdapter(busList));
    }
}